package com.skyline.jfs.namespace.dao.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;

import com.skyline.jfs.common.config.Config;
import com.skyline.jfs.namespace.dao.JFSDirectoryDao;
import com.skyline.jfs.namespace.mapper.JFSDirectoryMapper;
import com.skyline.jfs.namespace.model.JFSDirectory;

@Component("jfsDirectoryDao")
public class JFSDirectoryDaoImpl implements JFSDirectoryDao {

	@Autowired
	private JdbcTemplate jdbcTemplate;
	
	@Override
	public List<JFSDirectory> findAllSubDirsById(Long id) {
		String sql=Config.getSql("JFSDirectoryDao.findAllSubDirsById");
		return jdbcTemplate.query(sql, JFSDirectoryMapper.getMapper(), id);
	}

	@Override
	public JFSDirectory findDirByDir(String dir) {
		String sql=Config.getSql("JFSDirectoryDao.findDirByDir");
		List<JFSDirectory> dirs=jdbcTemplate.query(sql, JFSDirectoryMapper.getMapper(), dir);
		if(dirs!=null&&dirs.size()>0){
			return dirs.get(0);
		}else{
			return null;
		}
		//return jdbcTemplate.query(sql, JFSDirectoryMapper.getMapper(), dir).get(0);
	}
	
	@Override
	public JFSDirectory findDirByID(Long id){
		String sql=Config.getSql("JFSDirectoryDao.findDirById");
		JFSDirectory currentDir =null;
		try{
			currentDir=jdbcTemplate.queryForObject(sql, JFSDirectoryMapper.getMapper(), id);
		}catch(Exception e){
			e.printStackTrace();
		}
		return currentDir;
	}

	@Override
	public void insertDir(String dir) {
		// TODO Auto-generated method stub

	}
	
	@Override
	public void insertDir(Long parent, String path, String name,
			Integer permission){
		String sql=Config.getSql("JFSDirectoryDao.insertDir");
		jdbcTemplate.update(sql,parent,name,path,0,permission);
	}

	@Override
	public void deleteDir(Long id) {
		// TODO Auto-generated method stub

	}

	@Override
	public void deleteDir(String dir) {
		// TODO Auto-generated method stub

	}

	@Override
	public void updateName(Long id, String newName) {
		// TODO Auto-generated method stub

	}

	@Override
	public void updateName(String dir, String newName) {
		// TODO Auto-generated method stub

	}

	@Override
	public void updatePermission(Long id, Integer newPermission) {
		// TODO Auto-generated method stub

	}

	@Override
	public void updatePermission(String dir, Integer newPermission) {
		// TODO Auto-generated method stub

	}

}
